<template>
	<view class="page_forget">
		<!-- input输入框 -->
		<view class="input-group">
			<view class="input-row border-bottom">
				<image class="img" src="/static/login/phone.png" mode="widthFix"></image>
				<input class="input" type="number" v-model="mobile" placeholder="请输入手机号"
					placeholder-style="color:#BFBFBF;font-size:30rpx;" />
			</view>
			<view class="input-row border-bottom">
				<image class="img" src="/static/login/pw.png" mode="widthFix"></image>
				<input class="input code-input" type="number" maxlength="6" placeholder="请输入验证码" v-model="captcha"
					placeholder-style="color:#BFBFBF;font-size:30rpx;" />
				<button class="code-btn cu-btn bg-white get-button" @tap="sendCode">{{ CodeText }}</button>
			</view>
			<view class="input-row border-bottom">
				<image class="img" src="/static/login/pw.png" mode="widthFix"></image>
				<input class="input" type="password" v-model="newpassword" placeholder="请设置新密码" maxlength="12"
					placeholder-style="color:#BFBFBF;font-size:30rpx;" />
			</view>
			<view class="input-row border-bottom">
				<image class="img" src="/static/login/pw.png" mode="widthFix"></image>
				<input class="input" type="password" v-model="rpsw" placeholder="请再次输入新密码" maxlength="12"
					placeholder-style="color:#BFBFBF;font-size:30rpx;" />
			</view>
		</view>
		<view class="login-btn">
			<view class="subtn"><button type="primary" @click="userResetpwd">提交</button></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				newpassword: '',
				captcha: '',
				rpsw: '',
				CodeText: '获取验证码',
				CodeNumDown: 60,
			};
		},
		onLoad() {},
		methods: {
			userResetpwd() {
				let ph = /^[1][0-9]{10}$/;
				if (!ph.test(this.mobile)) {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的手机号'
					})
					return
				}
				if (!this.captcha) {
					uni.showToast({
						icon: 'none',
						title: '请输入验证码'
					})
					return
				}
				if (!this.newpassword) {
					uni.showToast({
						icon: 'none',
						title: '请输入新密码'
					})
					return
				}
				if (this.newpassword != this.rpsw) {
					uni.showToast({
						icon: 'none',
						title: '两次新密码不一致'
					})
					return
				}
				this.$http('user.userResetpwd', {
					mobile: this.mobile,
					captcha: this.captcha,
					newpassword: this.newpassword
				}, '重置中...').then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '密码重置成功',
							icon: 'success'
						});
						setTimeout(time => {
							uni.navigateBack({
								delta: 1
							});
						}, 1000);
					}else{
						this.CodeNumDown = 60;
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})
			},
			// 发送验证码
			sendCode() {
				let ph = /^[1][0-9]{10}$/;
				if (!ph.test(this.mobile)) {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的手机号'
					})
					return
				}
				this.downTime(this.CodeNumDown);
				let that = this;
				that.$http('user.smsSend', {
					mobile: this.mobile,
					event: 'resetpwd'
				}, '获取中...').then(res => {
					this.downTime(this.CodeNumDown)
					if (res.code === 1) {
						this.downTime(this.CodeNumDown);
					} else {
						uni.showToast({
							icon: 'error',
							title: res.msg
						})
					}
				});
			},
			downTime(num) {
				if (num === 0) {
					this.CodeText = '获取验证码';
					num = 60;
					this.CodeNumDown = num;
					return;
				} else {
					num--;
					this.CodeText = num + 's后发送';
					this.CodeNumDown = num;
				}
				var _this = this;
				setTimeout(function() {
					_this.downTime(num);
				}, 1000);
			}
		}
	};
</script>

<style lang="scss">
	.page {
		background-color: #F6F7F9;
	}

	/*input输入框*/
	.input-group {
		padding: 0upx 24upx;
		background-color: #fff;

		.input-row {
			position: relative;
			height: 96upx;
			display: flex;
			align-items: center;

			.img {
				width: 34rpx;
				height: 34rpx;
				margin-right: 30upx;
			}

			.input {
				width: 65%;
				font-size: 32rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: rgba(0, 0, 0, 0.85);
			}

			.code-input {
				width: 400upx;
			}

			.code-btn {
				font-size: 24upx;
				display: block;
				line-height: 64upx;
				position: absolute;
				right: 0;
				top: calc(50% - 32upx);
				color: #287E34;
				background-color: #fff;
			}
		}

		.input-row.border-bottom {
			border-bottom: 1rpx solid #EEEEEE;
		}
	}



	/*登录按钮*/
	.login-btn {
		width: 686rpx;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translate(-50%);

		.subtn {
			button {
				height: 98px;
				background: linear-gradient(93deg, #6FAD19 0%, #287E34 100%);
				width: 100%;
				height: 98rpx;
				text-align: center;
				line-height: 90rpx;
				border-radius: 49rpx;
				font-size: 32rpx;
				font-weight: 500;
				border: none;
				color: #fff;
			}
		}
	}
</style>